#ifndef _TEXTURE_RENDERER_H_
#define _TEXTURE_RENDERER_H_

#include "../GameObject/GameObject.h"
#include "../Resourse_manager/TextureAsset.h"
#include "../Resourse_manager/AssetManager.h"
#include "../Camera/Camera.h"
#include <memory>
#include <string>


class TextureRenderer : public Component
{
public:

    enum class RenderMode
    {
        Stretch,
        Tile,
        Center,
        FitWidth,
        FitHeight,
        KeepRatio
    };

    TextureRenderer(GameObject* gameObject);
    virtual ~TextureRenderer() = default;

    bool SetTexture(const std::string& textureId, const std::wstring& texturePath);
    bool SetTexture(const std::string& textureId);
    void ClearTexture();

    void SetRenderMode(RenderMode mode) { m_renderMode = mode; }
    RenderMode GetRenderMode() const { return m_renderMode; }

    void SetTextureOffset(float offsetX, float offsetY);
    float GetTextureOffsetX() const { return m_textureOffsetX; }
    float GetTextureOffsetY() const { return m_textureOffsetY; }

    void SetTextureScale(float scaleX, float scaleY);
    float GetTextureScaleX() const { return m_textureScaleX; }
    float GetTextureScaleY() const { return m_textureScaleY; }

    void SetAlpha(float alpha);
    float GetAlpha() const { return m_alpha; }

    void SetTintColor(int color) { m_tintColor = color; }
    int GetTintColor() const { return m_tintColor; }

    void SetTintEnabled(bool enabled) { m_tintEnabled = enabled; }
    bool IsTintEnabled() const { return m_tintEnabled; }

    void render() override;

    bool HasValidTexture() const;
    int GetTextureWidth() const;
    int GetTextureHeight() const;

    static void SetRenderingCamera(Camera* camera) { s_renderingCamera = camera; }
    static Camera* GetRenderingCamera() { return s_renderingCamera; }

private:
    std::shared_ptr<TextureAsset> m_textureAsset;
    std::string m_currentTextureId;
    AssetManager* m_assetManager;

    RenderMode m_renderMode;
    float m_textureOffsetX, m_textureOffsetY;
    float m_textureScaleX, m_textureScaleY;
    float m_alpha;
    int m_tintColor;
    bool m_tintEnabled;

    static Camera* s_renderingCamera;

    void RenderStretched();
    void RenderTiled();
    void RenderCentered();
    void RenderFitWidth();
    void RenderFitHeight();
    void RenderKeepRatio();

    void RenderImage(IMAGE* image, int x, int y, int width, int height);
    void RenderImageTiled(IMAGE* image, int x, int y, int width, int height);
};

#endif // !_TEXTURE_RENDERER_H_
